<?php

namespace App\Transformers;
use League\Fractal\TransformerAbstract;
use Illuminate\Support\Str;
use App\Models\User;
use Illuminate\Notifications\DatabaseNotification;
class NotificationTransformer extends TransformerAbstract
{
    public function transform(DatabaseNotification $notific)
    {
        if ($notific->type === 'App\Notifications\UserFollowed') {
            $user_info = $notific->data;
            return [
                'user_id' => $user_info['user_id'],
                'user_name' => $user_info['user_name'],
                'user_avatar' => Str::startsWith($user_info['user_avatar'], 'http') ? $user_info['user_avatar'] : 'https://pic.touxiangge.com/' . $user_info['user_avatar'],
                'read_at' => (string) $notific->read_at,
                'created_at' => (string) $notific->created_at,
                'updated_at' => (string) $notific->updated_at
            ];
        }
    }
}
